package com.foreknow.elmboot.controller;


import com.foreknow.elmboot.po.DeliveryAddress;
import com.foreknow.elmboot.service.DeliveryAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/DeliveryAddressController")
public class DeliveryAddressController {

    @Autowired
    private DeliveryAddressService service;

//    根据用户id查询所有地址
    @RequestMapping("/listDeliveryAddressByUserId")
    public Object listDeliveryAddressByUserId(DeliveryAddress deliveryAddress){
        List<DeliveryAddress> deliveryAddresses = service.listDeliveryAddressByUserId(deliveryAddress.getUserId());
        return  deliveryAddresses;
    }

//    根据daId查询地址
    @RequestMapping("/getDeliveryAddressById")
    public Object getDeliveryAddressByUserId(DeliveryAddress deliveryAddress){
        DeliveryAddress deliveryAddressByUserId = service.getDeliveryAddressById(deliveryAddress.getDaId());
        return  deliveryAddressByUserId;
    }

//    添加地址
    @RequestMapping("/saveDeliveryAddress")
    public Object saveDeliveryAddress(DeliveryAddress deliveryAddress){
        return service.saveDeliveryAddress(deliveryAddress);

    }

//    修改地址
    @RequestMapping("/updateDeliveryAddress")
    public Object updateDeliveryAddress(DeliveryAddress deliveryAddress){
        return service.updateDeliveryAddress(deliveryAddress);

    }

//    删除地址
    @RequestMapping("/removeDeliveryAddress")
    public Object removeDeliveryAddress(DeliveryAddress deliveryAddress){
        return service.removeDeliveryAddress(deliveryAddress.getDaId());

    }


}
